import requests


class IHRMDepartmentApi:

    # 封装部门接口
    @classmethod
    def add_department_api(cls, token, department_body):
        department_url = 'http://ihrm2-test.itheima.net/api/company/department'
        department_header = {'Content-Type': 'application/json',
                             'Authorization': token}
        department_resp = requests.post(url=department_url, headers=department_header, json=department_body)
        return department_resp

    # 封装查询接口
    @classmethod
    def query_department_api(cls, token, department_id):
        query_department_url = f'http://ihrm2-test.itheima.net/api/company/department/{department_id}'
        query_department_header = {'Authorization': token}
        query_department_resp = requests.get(url=query_department_url, headers=query_department_header)
        return query_department_resp

    # 封装修改方法
    @classmethod
    def update_department_api(cls, token, department_id, update_department_body):
        update_department_url = f'http://ihrm2-test.itheima.net/api/company/department/{department_id}'
        update_department_header = {'Content-Type': 'application/json',
                                    'Authorization': token}
        update_department_resp = requests.put(url=update_department_url, headers=update_department_header,
                                              json=update_department_body)
        return update_department_resp

    # 封装删除的方法
    @classmethod
    def delete_department_api(cls, token, department_id):
        delete_department_url = f"http://ihrm2-test.itheima.net/api/company/department/{department_id}"
        delete_department_header = {'Authorization': token}
        delete_department_resp = requests.delete(url=delete_department_url, headers=delete_department_header)
        return delete_department_resp
